<template>
    <div class="qingwu">
        <div class="admin_table_page_title">说说列表</div>
        <div class="unline underm"></div>

        <div class="admin_table_handle_btn">
            <a-form layout="inline" :form="form" @submit="handleSubmit">
                <a-form-item label="标签">
                    <a-select @change="handleChange" style="width: 120px" default-value="请选择标签" v-model="label_id">
                        <a-select-option :value="value.id" v-for="(value,index) in label_lists"
                                         :key="index">
                            {{ value.title }}
                        </a-select-option>
                    </a-select>
                </a-form-item>
                <a-form-model-item>
                    <a-button icon="search" @click="search">
                        查询
                    </a-button>
                </a-form-model-item>
                <a-form-model-item>
                    <a-button @click="reset">重置</a-button>
                </a-form-model-item>
            </a-form>
        </div>

        <div class="admin_table_handle_btn">
            <a-button type="danger" icon="delete" @click="del">批量删除</a-button>
        </div>
        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :pagination="false"
                     :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" row-key="id">
                <span slot="action" slot-scope="rows">
                    <a-button icon="file-search" @click="$router.push('/Estate/circle/form/'+rows.id)">查看评论</a-button>
                </span>

                <span slot="label" slot-scope="rows">
                    <div class="admin_goods_pic_txt">
                        <div><div v-for="(value, index) in rows.label ">#{{value}}</div></div>
                    </div>
                </span>

                <span slot="name" slot-scope="rows">
                    <div class="admin_goods_pic_txt">
                        <div class="img"><img v-if="rows.images.length" :src="rows.images[0]"><a-icon v-else type="picture"/></div>
                    </div>
                </span>
            </a-table>
            <div class="admin_pagination" v-if="total>0">
                <a-pagination v-model="params.page" :page-size.sync="params.limit" :total="total" @change="onChange" show-less-items/>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        components: {},
        props: {},
        data() {
            return {
                params: {
                    page: 1,
                    limit: 30,
                },
                total: 0, //总页数
                selectedRowKeys: [], // 被选择的行
                columns: [
                    {title: '#', dataIndex: 'id', fixed: 'left'},
                    {title: '用户ID', dataIndex: 'user_id'},
                    {title: '点赞量', dataIndex: 'star'},
                    {title: '内容', dataIndex: 'content'},
                    {title: '图片', scopedSlots: {customRender: 'name'}},
                    {title: '标签', scopedSlots: {customRender: 'label'}},
                    {title: '发布时间', dataIndex: 'created_at'},
                    {title: '操作', key: 'id', fixed: 'right', scopedSlots: {customRender: 'action'}},
                ],
                list: [],
                label_id: '',   // 标签ID
                label_lists: []
            };
        },
        watch: {},
        computed: {},
        methods: {
            // 选择框被点击
            onSelectChange(selectedRowKeys) {
                this.selectedRowKeys = selectedRowKeys;
            },
            // 选择分页
            onChange(e) {
                this.params.page = e;
                this.onload();
            },
            // 删除
            del() {
                if (this.selectedRowKeys.length == 0) {
                    return this.$message.error('未选择数据.');
                }
                this.$confirm({
                    title: '你确定要删除选择的数据？',
                    content: '确定删除后无法恢复.',
                    okText: '是',
                    okType: 'danger',
                    cancelText: '取消',
                    onOk: () => {
                        let ids = this.selectedRowKeys.join(',');
                        this.$delete(this.$api.estateCircleList + '/' + ids).then(res => {
                            if (res.code == 200) {
                                this.onload();
                                this.$message.success('删除成功');
                            } else {
                                this.$message.error(res.msg)
                            }
                        });

                    },
                });
            },
            onload() {
                this.$get(this.$api.estateCircleList, this.params).then(res => {
                    this.total = res.data.total;
                    this.list = res.data.data;
                });
            },
            // 重置
            reset() {
                location.reload();
            },
            // 获取标签列表
            getCommunityList() {
                this.$get(this.$api.estateLabelListAll).then(res => {
                    this.label_lists = res.data;
                })
            },
            // 搜索
            search() {
                this.params['label_id'] = this.label_id;
                this.$get(this.$api.circleList, this.params).then(res => {
                    this.total = res.data.total;
                    this.list = res.data.data;
                });
            },
        },
        created() {
            this.onload();
            this.getCommunityList();
        },
        mounted() {
        }
    };
</script>
<style lang="scss" scoped>

</style>
